﻿
EditClass = function () {
    var self = this;
    self.CloseWindow = function (button) {
        //var win = this.window.parent.Ext.getCmp(windowId);
        var win = button.up("window");
        win.close();
    };

    self.PostBackSuccess = function (response, result) {
        if (result.success) {
            this.up("window").close();
            var tab = App.ExampleTabs.getActiveTab();
            if (tab) {
                tab.down("grid").getStore().reload();
            }
        }
    };

    self.submitReady = function (button) {
        var form = button.up("form").getForm();
        var fields = form.getFields();
        for (var i = 0; i < fields.getCount() ; i++) {
            var field = fields.getAt(i);
            if (field.getXType() == 'htmleditor')
                field.setValue(Ext.String.htmlEncode(field.getValue()));
            else if (field.getXType() == 'combobox') {
                if (!(field.getValue()))
                    field.setValue(field.getRawValue());
            }
            else if (field.getXType() == 'netdropdown') {

                //field.setRawValue(field.getValue());
                //field.setValue(field.getRawValue());

            }
        }
    }


    self.SetDropdownList = function (dropdownlist, record) {
        dropdownlist.setValue(record.raw.id, record.raw.text, false);
        Ext.getCmp(dropdownlist.valueHiddenName).setValue(record.raw.id);

    }

    var navigate = function (panel, direction) {
        var layout = panel.getLayout();
        layout[direction]();
        if (direction == "next" && layout.activeItem.itemId == "LC") {
            var tree = panel.down("#selectedTree").down("treeview");

            var store = panel.down("#employeeGrid").getStore();
            store.proxy.extraParams = {
                orgIds: tree.dataSource.data.keys
            };

            store.reload();
        }
        if (Ext.getCmp('prevButton'))
            Ext.getCmp('prevButton').setDisabled(!layout.getPrev());
        if (Ext.getCmp('nextButton'))
            Ext.getCmp('nextButton').setDisabled(!layout.getNext());
    };
    function GetOrgs(node, orgjson) {
        var orderindex = 0;
        node.eachChild(function (child) { //循环下一级的所有子节点 

            var json = '{ "OrgId":"' + child.data.id + '","ParentId":"' + child.data.parentId + '","OrderIndex":' + orderindex + '}';

            orderindex++;
            orgjson.push(JSON.parse(json));

            GetOrgs(child, orgjson); //递归选中子节点 
        });
    }
}
